package com.zhz.employee.biz;

import com.zhz.common.enums.BizResponseEnum;
import com.zhz.common.utils.ConvertUtils;
import com.zhz.employee.contract.request.EmployeeFindLeaveRequest;
import com.zhz.employee.contract.request.EmployeeSaveLeaveRequest;
import com.zhz.employee.contract.request.EmployeeTransferPositionRequest;
import com.zhz.employee.repository.service.EmployeeResignationService;
import com.zhz.model.employee.contract.dto.EmployeeResignationDTO;
import com.zhz.model.employee.contract.param.EmployeeResignationQueryParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * 员工离职业务处理service
 *
 * @author zhouhengzhe
 * @date 2023/5/30
 */
@Component
public class EmployeeResignationBizService {

    private final EmployeeResignationService employeeResignationService;

    @Autowired
    public EmployeeResignationBizService(EmployeeResignationService employeeResignationService) {
        this.employeeResignationService = employeeResignationService;
    }

    /**
     * 离职
     *
     * @param employeeSaveLeaveRequest 离职请求
     */
    public void saveLeave(EmployeeSaveLeaveRequest employeeSaveLeaveRequest) {
        EmployeeResignationDTO employeeResignationDTO = ConvertUtils.sourceToTarget(employeeSaveLeaveRequest, EmployeeResignationDTO.class);
        employeeResignationService.save(employeeResignationDTO);
    }

    /**
     * 离职表单读取
     *
     * @param employeeFindLeaveRequest 离职表单读取请求
     * @return 离职表单读取响应
     */
    public EmployeeResignationDTO findLeave(EmployeeFindLeaveRequest employeeFindLeaveRequest) {
        EmployeeResignationDTO resignationDto = employeeResignationService.getOne(EmployeeResignationQueryParam.builder().id(employeeFindLeaveRequest.getId()).build());
        BizResponseEnum.USER_RESIGNATION_NOT_EXIST.assertNotNull(resignationDto);
        return resignationDto;
    }

    /**
     * 调岗表单保存
     *
     * @param employeeTransferPositionRequest 调岗表单保存请求
     */
    public void saveTransferPosition(EmployeeTransferPositionRequest employeeTransferPositionRequest) {
        EmployeeResignationDTO employeeResignationDTO = ConvertUtils.sourceToTarget(employeeTransferPositionRequest, EmployeeResignationDTO.class);
        employeeResignationService.save(employeeResignationDTO);
    }
}
